#!/bin/bash
# 工单编号：大数据-电商数仓-09-流量主题店内路径看板
# 功能：批量加载75天ods数据及dim全量数据

# -------------------------- 1. 基础配置 --------------------------
HDFS_BASE_PATH="/warehouse/shop_path/ods"  # Hive ODS层HDFS路径
LOCAL_CSV_PATH="/opt/data/user_click_data"  # 本地CSV文件存放路径
DIM_HDFS_PATH="/warehouse/shop_path/ods"  # Hive DIM层HDFS路径

# -------------------------- 2. 加载dim层全量数据（仅执行1次） --------------------------
#echo "开始加载dim层全量数据..."
#hive -e "
#use shop_path;
#"

## dim_page_info
#hive -e "
#LOAD DATA LOCAL INPATH '${LOCAL_CSV_PATH}/dim_page_info_full.csv' 
#OVERWRITE INTO TABLE ods_page_info;
#"

# dim_time
#hive -e "
#LOAD DATA LOCAL INPATH '${LOCAL_CSV_PATH}/dim_time_full.csv' 
#OVERWRITE INTO TABLE ods_time;
#"

# dim_shop_info
#hive -e "
#LOAD DATA LOCAL INPATH '${LOCAL_CSV_PATH}/dim_shop_info_full.csv' 
#OVERWRITE INTO TABLE ods_shop_info;
#"
#echo "dim层全量数据加载完成！"

# -------------------------- 3. 加载ods层75天数据 --------------------------
# 日期范围：20250127-20250411
START_DATE='20250127'
END_DATE='20250411'

# 循环加载每日数据
current_date=$START_DATE
while [ "$current_date" -le "$END_DATE" ]; do
    echo "开始加载 ${current_date} 的ods数据..."

    # 3.1 加载ods_visitor_behavior_di
   # hive -e "
#use shop_path;
 #   LOAD DATA LOCAL INPATH '${LOCAL_CSV_PATH}/ods_visitor_behavior_di_${current_date}.csv' 
  #  OVERWRITE INTO TABLE ods_visitor_behavior_di 
   # PARTITION (dt=${current_date});
    #"

    # 3.2 加载ods_page_info_df
#    hive -e "
#use shop_path;
#    LOAD DATA LOCAL INPATH '${LOCAL_CSV_PATH}/ods_page_info_df_${current_date}.csv' 
 #   OVERWRITE INTO TABLE ods_page_info_df 
  #  PARTITION (dt=${current_date});
   # "

    # 3.3 加载ods_order_relation_di
   # hive -e "
#use shop_path;
 #   LOAD DATA LOCAL INPATH '${LOCAL_CSV_PATH}/ods_order_relation_di_${current_date}.csv' 
  #  OVERWRITE INTO TABLE ods_order_relation_di 
   # PARTITION (dt=${current_date});
    #"

   # # 3.4 加载ods_shop_info_df
    #hive -e "
#use shop_path;
 #   LOAD DATA LOCAL INPATH '${LOCAL_CSV_PATH}/ods_shop_info_df_${current_date}.csv' 
  #  OVERWRITE INTO TABLE ods_shop_info_df 
   # PARTITION (dt=${current_date});
    #"

   # 3.5 加载 ods_user_click_log
    hive -e "
    use shop_path;
    LOAD DATA LOCAL INPATH '${LOCAL_CSV_PATH}/ods_user_click_log_${current_date}.csv'
    OVERWRITE INTO TABLE ods_user_click_log
    PARTITION (dt=${current_date});
    "

    echo "${current_date} 的ods数据加载完成！"

    # 计算下一天日期（需安装dateutils工具，或用Python辅助计算）
    current_date=$(date -d "$current_date +1 day" +%Y%m%d)
done

echo "75天ods数据全部加载完成！"
